package com.sanpu.kxe.business.member.model;

import com.alibaba.fastjson.JSONObject;
import com.sanpu.kxe.business.member.bean.MemberBannerOutput;
import com.sanpu.kxe.business.member.bean.MemberDetailsOutput;
import com.sanpu.kxe.business.member.bean.MemberLevelOutput;
import com.sanpu.kxe.business.member.bean.MemberPayTypeOutput;
import com.sanpu.kxe.business.member.bean.MemberPaymentOutput;
import com.sanpu.kxe.business.member.bean.MemberProductRateOutput;
import com.sanpu.kxe.business.member.bean.MemberPromotOutput;
import com.sanpu.kxe.business.member.bean.MemberSpreadOutput;
import com.sanpu.kxe.business.member.bean.MemberTeamNumberOutput;
import com.sanpu.kxe.business.member.bean.MemberTeamOutput;
import com.sanpu.kxe.rxservice.DataUtils;
import com.sanpu.kxe.rxservice.client.MemberClient;

import java.util.List;

import rx.Observable;

/**
 * Description：会员模块model
 * Created by 薛勇军 on 2018/7/30.
 */

public class MemberModel {

    private static volatile MemberModel mInstance;

    private MemberModel() {
        if (mInstance != null) {
            throw new IllegalStateException("Already initialized.");
        }
    }

    public static MemberModel getInstance() {
        MemberModel result = mInstance;
        if (result == null) {
            synchronized (MemberModel.class) {
                result = mInstance;
                if (result == null) {
                    mInstance = result = new MemberModel();
                }
            }
        }
        return result;
    }

    /**
     * 会员等级列表
     */
    public Observable<List<MemberLevelOutput>> memberLevelList() {
        return MemberClient.getInstance().memberLevelList();
    }

    /**
     * 会员升级广告栏
     */
    public Observable<List<MemberBannerOutput>> memberUpgrade() {
        return MemberClient.getInstance().memberUpgrade();
    }

    /**
     * 会员等级详情
     */
    public Observable<MemberDetailsOutput> memberLevelDetail() {
        return MemberClient.getInstance().memberLevelDetail();
    }

    /**
     * 会员等级详情
     */
    public Observable<MemberPaymentOutput> paymentDictinary() {
        return MemberClient.getInstance().paymentDictinary();
    }

    /**
     * 余额升级会员
     */
    public Observable<String> balanceUpgrade(int lvlId) {
        JSONObject reqData = new JSONObject();
        reqData.put("lvlId", lvlId);
        return MemberClient.getInstance().balanceUpgrade(reqData);
    }

    /**
     * 获取会员充值信息列表
     */
    public Observable<List<MemberLevelOutput>> findVipConfList() {
        return MemberClient.getInstance().findVipConfList();
    }

    /**
     * 获取会员推广列表
     */
    public Observable<List<MemberSpreadOutput>> getMemberSpreadList() {
        return MemberClient.getInstance().getMemberSpreadList();
    }

    /**
     * 充值会员方式列表
     */
    public Observable<List<MemberPayTypeOutput>> upgradeVipTypeList() {
        return MemberClient.getInstance().upgradeVipTypeList();
    }

    /**
     * 新版余额升级会员
     */
    public Observable<String> balanceUpgradeVip(String amount, String vipOpenId, String payPassword, String userName) {
        JSONObject reqData = new JSONObject();
        reqData.put("vipOpenId", vipOpenId);
        reqData.put("payPassword", DataUtils.getMD5Str(payPassword + userName));
        reqData.put("amount", amount);
        return MemberClient.getInstance().balanceUpgradeVip(reqData);
    }

    /**
     * 我的用户列表
     */
    public Observable<List<MemberPromotOutput>> myUserList(String merchantLevel, int nowPage) {
        JSONObject reqData = new JSONObject();
        reqData.put("merchantLevel", merchantLevel);
        reqData.put("nowPage", nowPage);
        return MemberClient.getInstance().myUserList(reqData);
    }

    /**
     * 搜索用户
     */
    public Observable<MemberPromotOutput> findUser(String merchantLevel, String phoneNumber) {
        JSONObject reqData = new JSONObject();
        reqData.put("merchantLevel", merchantLevel);
        reqData.put("phoneNumber", phoneNumber);
        return MemberClient.getInstance().findUser(reqData);
    }

    /**
     * 产品费率列表
     */
    public Observable<List<MemberProductRateOutput>> productRateList() {
        return MemberClient.getInstance().productRateList();
    }

    /**
     * 我的团队人数
     */
    public Observable<MemberTeamNumberOutput> myTeamNumber(String merchantCode) {
        JSONObject reqData = new JSONObject();
        reqData.put("merchantCode", merchantCode);
        return MemberClient.getInstance().myTeamNumber(reqData);
    }

    /**
     * 我的团队列表
     */
    public Observable<List<MemberTeamOutput>> myTeamList(int nowPage, String queryType, String merchantCode) {
        JSONObject reqData = new JSONObject();
        reqData.put("nowPage", nowPage);
        reqData.put("queryType", queryType);
        reqData.put("merchantCode", merchantCode);
        return MemberClient.getInstance().myTeamList(reqData);
    }
}
